package mqigdcom.mqigd.core;

import android.annotation.TargetApi;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent;
import android.os.Build;

import mqigdcom.mqigd.utils.LogUtils;
import mqigdcom.mqigd.utils.Utils;

/**
 * 监听网络连接状态的JobService
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class NetworkStatusJobService extends JobService {

    private static final String TAG = NetworkStatusJobService.class.getSimpleName();

    @Override
    public boolean onStartJob(JobParameters params) {
        if (Utils.isNetworkAvailable(this)) {
            LogUtils.d(TAG, "onStartJob() isNetworkAvailable = " + true);
            // 同步本地存储的数据到服务器端
            Intent service = new Intent(this, SyncDataService.class);
            startService(service);
            jobFinished(params, false);
        } else {
            LogUtils.d(TAG, "onStartJob() isNetworkAvailable = " + false);
            jobFinished(params, true);
        }
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        return false;
    }
}
